#!/usr/bin/perl -w

use Test::More tests => 5;

# =============================================================
# Cargamos el modulo
# ==============================================================
use_ok('Bench::Test::Remote');

# =============================================================
# Comprobamos que la creacion del objeto es correcta
# =============================================================
SKIP: {
   my $host = $ENV{BENCH_TEST_REMOTE_HOST}
      or skip('because you must set enviroment var BENCH_TEST_REMOTE_HOST', 4);

   my $remote = Bench::Test::Remote->new (
      HOST       => $ENV{BENCH_TEST_REMOTE_HOST},
      WORKDIR    => '.',
      EXECUTABLE => 'echo',
   );
   
   $remote->connect;

   isa_ok($remote, 'Bench::Test::Remote');
   # =============================================================
   # El comando echo es ejecutado en la maquina
   # remota. La salida debe ser igual a la entrada.
   # ==============================================================
   my $params = 'Give me five!';
   is($remote->get_result($params), "Give me five!\n", 'Correct output for getresult');

   # =============================================================
   # Redefinimos el metodo GET_RESULT y comprobamos su
   # funcionamiento
   # =============================================================
   $remote = Bench::Test::Remote->new (
      HOST        => $ENV{BENCH_TEST_REMOTE_HOST},
      WORKDIR     => '.',
      GET_RESULT  => sub { return "Get result given by user";  },
      SAVE_RESULT => sub { return "Save result given by user"; },
      EXECUTABLE  => 'echo',
   );

   is($remote->get_result,  'Get result given by user',  'Overwritting get_result');
   is($remote->save_result, 'Save result given by user', 'Overwritting save_result');
}
